package cn.tedu.review;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

/*复习继承自Collection与List独有的方法*/
public class TestList {
    public static void main(String[] args) {
        //创建多态对象
        Collection<String> List1 = new ArrayList();
        List<String> list = new ArrayList<>();
        //向list集合添加元素
        list.add("大力娃");
        list.add("千顺娃");
        list.add("头铁娃");
        list.add("喷火娃");
        list.add("喷水娃");
        list.add("隐身娃");
        list.add("小紫娃");
        System.out.println(list);
        List<String> list2 = new ArrayList<>();
        //向list集合添加元素
        list2.add("大力娃");
        list2.add("千顺娃");
        list2.add("头铁娃");
        list2.add("喷火娃");
        list2.add("喷水娃");
        list2.add("隐身娃");
        list2.add("小紫娃");
        System.out.println(list2);

        //list.clear();//清空集合
//        System.out.println(list);
        System.out.println(list.contains("白骨精"));//判断是否包含指定的元素
        System.out.println(list.equals("大力娃"));
        System.out.println(list.equals(list2));
        System.out.println(list.hashCode());
        System.out.println(list.isEmpty());
        System.out.println(list.remove("隐身娃"));
        System.out.println(list);
        System.out.println(list.size());
        System.out.println(Arrays.toString(list2.toArray()));

        //创建第3个集合
        List<String> list3 = new ArrayList<>();
        list3.add("1");
        list3.add("2");
        list3.add("3");
        list3.add("4");
        System.out.println(list3);

        System.out.println(list.addAll(list3));
        System.out.println(list);
        System.out.println(list.containsAll(list3));

        System.out.println(list.retainAll(list3));

        System.out.println(list);

        System.out.println(list.removeAll(list3));
        //删除list集合中的所有元素
        System.out.println(list);
        System.out.println(list.addAll(list2));

        list.add(1,"小蝴蝶");
        list.add(5,"小蝴蝶");
        System.out.println(list);
        System.out.println(list.indexOf("小蝴蝶"));
        System.out.println(list.lastIndexOf("小蝴蝶"));

        System.out.println(list.remove(5));
        System.out.println(list);

        System.out.println(list.get(7));//获取指定下标处的元素
        System.out.println(list.set(0,"狗娃子"));
        System.out.println(list);
        //将list2的所有元素添加到list的指定下标处
        System.out.println(list.addAll(0,list2));
        System.out.println(list);
    }
}
